package com.xiyu.service.repository.market.task;

import com.xiyu.service.model.market.task.MarketTaskReceiver;
import com.xiyu.service.model.market.task.MarketTaskReceiverTable;
import org.babyfish.jimmer.spring.repository.JRepository;

import java.util.Optional;
import java.util.List;

public interface MarketTaskReceiverRepository extends JRepository<MarketTaskReceiver, Long> {
    MarketTaskReceiverTable marketTaskReceiverTable = MarketTaskReceiverTable.$;

    default void updateMarketMailId(Long taskId, String mailAddress, String marketMailId, String messageId){
        sql().createUpdate(marketTaskReceiverTable)
                .where(marketTaskReceiverTable.id().eq(taskId))
                .where(marketTaskReceiverTable.mailAddress().eq(mailAddress))
                .set(marketTaskReceiverTable.marketMailId(), marketMailId)
                .set(marketTaskReceiverTable.messageId(), messageId)
                .execute();
    }

    Optional<MarketTaskReceiver> findByMarketMailId(String marketMailId);

    Optional<MarketTaskReceiver> findByMessageId(String messageId);

    List<MarketTaskReceiver> findByTaskId(Long taskId);

}